package com.hongshan.wallet.core.wallet

import android.app.Application
import android.databinding.ObservableField
import android.view.View
import android.widget.TextView
import com.hongshan.wallet.Constant
import com.hongshan.wallet.MyApplication
import com.hongshan.wallet.base.MyViewModel
import com.hongshan.wallet.copyStr
import com.hongshan.wallet.router.RouterIndex
import com.hongshan.wallet.router.go
import com.hongshan.wallet.util.checkRealNameAndPwdStatus

/**
 * Copyright Zhangxx.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.wallet
 * @author   : zhangxx
 * @date     : 2019/3/22
 * @email    : qq957413212@hotmail.com
 */
class WalletViewModel(application: Application) :MyViewModel(application) {

    val balance = ObservableField<String>(MyApplication.userInfo.get()?.commission_balance)
    val commision = ObservableField<String>("累计佣金 ${MyApplication.userInfo.get()?.cumulative_commission} 元")

    val toBalance = View.OnClickListener {
        if (checkRealNameAndPwdStatus()) return@OnClickListener
        go(RouterIndex.BALANCE_INTO)
    }

    val commisionDesc = View.OnClickListener {
        go(RouterIndex.COMMISSIONS)
    }

    val security = View.OnClickListener {
        go(RouterIndex.SECURITY_SETTING)
    }

    val account = View.OnClickListener {
        go(RouterIndex.ACCOUNT_MANAGE)
    }

    val invite = View.OnClickListener {
        go(
            RouterIndex.WEB,
            mapOf(
                "url" to "file:///android_asset/my-invite.html",
                Constant.ROUTE_PARAMS_KEY.WEB_ACTION to Constant.ROUTE_PARAMS_KEY.ACTION_MY_INVITE
            )
        )
    }

    val help = View.OnClickListener {
//        go(RouterIndex.HELP_CENTER)
        go(RouterIndex.WEB, mapOf("url" to "${Constant.HttpApi.BASE_URL}help_center"))
    }

    val setting = View.OnClickListener {
        go(RouterIndex.SETTING)
    }

    val copy = View.OnClickListener {
        val text = (it as TextView).text.toString()
        copyStr(text.substring(3,text.length))
    }

}